<?php
$fd = stream_socket_pair(AF_UNIX,SOCK_DGRAM,0);
$fd[0];
$fd[1];

$pid = pcntl_fork();
if ($pid==0){
    while (1){
      $data =  fread($fd[0],128);
      if ($data){
          fprintf(STDOUT,"recv data:%s\n",$data);
      }
      if (strncasecmp(trim($data),"quit",4)==0){
          break;
      }
    }
    exit(0);
}

while (1) {
        $data = fread(STDIN, 128);
        if ($data) {
            fwrite($fd[1], $data, strlen($data));
        }
        if(strncasecmp($data,"quit",4)==0){
            break;
        }
    }
$pid = pcntl_wait($status);
fprintf(STDOUT,"exit pid=%d\n",$pid);